<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="水泥浆体积(m³)" prop="volume">
				<u-input :border="border" placeholder="请输入水泥浆体积" v-model="model.volume" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="设计灰浆密度(kg/m³)" prop="slurryDensity">
				<u-input :border="border" placeholder="请输入设计灰浆密度" v-model="model.slurryDensity" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="干水泥用量(kg)" prop="cementWeight">
				<u-input :border="border" placeholder="请输入干水泥用量" v-model="model.cementWeight" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="清水密度(kg/m³)" prop="waterDensity">
				<u-input :border="border" placeholder="请输入清水密度" v-model="model.waterDensity" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;"  :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="配灰用清水量" prop="waterVolume">
					<span v-if="model.waterVolume"> {{model.waterVolume}} m³ </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">Q = (V × ρ2 - G) ÷ ρ1</view>
				<view class="u-item-desc">式中：Q — 清水量，单位 m³</view>
				<view class="u-item-desc">V — 水泥浆体积，单位 m³</view>
				<view class="u-item-desc">ρ2 — 设计灰浆密度，单位 kg/m³</view>
				<view class="u-item-desc">G — 干水泥用量，单位 kg</view>
				<view class="u-item-desc">ρ1 — 清水密度，单位 kg/m³</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					volume: '',
					slurryDensity: '',
					cementWeight: '',
					waterDensity: '',
					waterVolume: ''
				},
				rules: {
					volume: [{
						required: true,
						message: '请输入水泥浆体积',
						trigger: 'blur'
					}],
					slurryDensity: [{
						required: true,
						message: '请输入设计灰浆密度',
						trigger: 'blur'
					}],
					cementWeight: [{
						required: true,
						message: '请输入干水泥用量',
						trigger: 'blur'
					}],
					waterDensity: [{
						required: true,
						message: '请输入清水密度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						const V = parseFloat(this.model.volume);
						const ρ2 = parseFloat(this.model.slurryDensity);
						const G = parseFloat(this.model.cementWeight);
						const ρ1 = parseFloat(this.model.waterDensity);
						
						// Q = (V × ρ2 - G) ÷ ρ1
						this.model.waterVolume = ((V * ρ2 - G) / ρ1).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>